home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ 2⁄23⁄90 / 0700-Re Persistent Object-Feb90 < prev    next >
Encoding:
Text File  |  1990-02-23  |  3.8 KB  |  115 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  A33          to A34
  2.  
  3. Item    3266425                         17-Feb-90        03:04PST
  4.  
  5. From:   D5295                           Reseach SW Design, D Goldman,PRT
  6.  
  7. To:     MACAPP.TECH$                    MacApp Technical
  8.  
  9. Sub:    Re: Persistent Objects
  10.  
  11. Just to see if I'm following this all correctly, could somebody tell me whether
  12. the following would take care of the "Which fields get displayed by the
  13. debugger?" and "Which fields get saved/restored for persistent objects?"
  14. questions…?
  15.  
  16.  
  17. Suppose that there is a metadata table (stored with the application, but only
  18. loaded into memory when needed) which contains the name, offset, and type of
  19. each field for each class.
  20.  
  21. Add these two methods to TObject:
  22. -----------------------------------------------------------------------------
  23. PROCEDURE TObject.ClassFields(debugging: BOOLEAN;
  24.                               theClass: ObjClassID;
  25.                               DoToField(fieldName: Str255; fieldAddr: Ptr;
  26.                                         fieldType: INTEGER));
  27.      VAR     itsName:   Str255;
  28.              itsAddr:   Ptr;
  29.              itsType:   INTEGER;
  30.  
  31.      BEGIN
  32.  
  33.     {$IFC qDebug}
  34.      IF debugging THEN
  35.          BEGIN
  36.          GetClassNameFromID(theClass, itsName);
  37.          DoToField(itsName, NIL, bClass);
  38.     {$ENDC}
  39.  
  40.      FOR <each field of theClass, according to metadata table> DO
  41.          BEGIN
  42.          <look up itsName, itsAddr, and itsType>;
  43.          DoToField(itsName, itsAddr, itsType);
  44.          END;
  45.  
  46.      END;
  47.  
  48.  
  49. PROCEDURE TObject.EachFieldDo(debugging: BOOLEAN;
  50.                               DoToField(fieldName: Str255; fieldAddr: Ptr;
  51.                                         fieldType: INTEGER));
  52.      PROCEDURE DoFields(theClass: ObjClassID);
  53.          BEGIN
  54.          ClassFields(debugging, theClass, DoToField);
  55.          END;
  56.  
  57.      BEGIN
  58.      DoFields(SELF.GetClass);
  59.      ForAllSuperClassesDo(DoFields);
  60.      END;
  61. -----------------------------------------------------------------------------
  62.  
  63. Having MacApp use EachFieldDo in its Inspector and Read/Write-persistent-object
  64. methods would therefore provide the correct default behaviors.
  65.  
  66.  
  67.  
  68. Now if you want to change the  behaviors for a particular class, you override,
  69. thus:
  70. -----------------------------------------------------------------------------
  71. PROCEDURE TMyObject.ClassFields(debugging: BOOLEAN;
  72.                                 theClass: ObjClassID;
  73.                                 DoToField(fieldName: Str255; fieldAddr: Ptr;
  74.                                           fieldType: INTEGER)); OVERRIDE;
  75.      BEGIN
  76.      IF theClass = SELF.GetClass THEN
  77.          BEGIN
  78.  
  79.         {$IFC qDebug}
  80.          IF debugging THEN    { Header, and non-"persistent" fields… }
  81.               BEGIN
  82.               DoToField('TMyObject', NIL,        bClass);
  83.               DoToField('fieldN1',   @fieldN1,   bTypeN1);
  84.                 :
  85.               DoToField('fieldNn',   @fieldNn,   bTypeNn);
  86.               END;
  87.         {$ENDC}
  88.  
  89.          DoToField('fieldP1',   @fieldP1,   bTypeP1);   { These are my  }
  90.            :                                            {  "persistent" }
  91.          DoToField('fieldPn',   @fieldPn,   bTypePn);   {  fields…      }
  92.  
  93.          END
  94.      ELSE
  95.          INHERITED ClassFields(theClass, DoToField);
  96.      END;
  97. -----------------------------------------------------------------------------
  98.  
  99. Did I get that right?
  100.  
  101. -- Dave (too lazy to be on MacApp.Tech$) Goldman, D5295
  102.    Research Software Design
  103.  
  104.  
  105.  
  106. Guerrilla P.S.:
  107.  
  108. Although it is obvious that the metadata table of field info should be
  109. generated by the compiler and linker, that doesn't mean that we couldn't --
  110. while we're waiting -- generate it ourselves by calling an appropriate
  111. "registration" routine for each and every field of each and every class at
  112. application-initialization time. (Of course, this stopgap measure could
  113. probably make use of existing Fields methods.)
  114.  
  115.